﻿using System;
using System.Linq;
using Domain;
using Domain.Entity;

namespace EmailMarketingDao
{
    public class QQEmailDao
    {
        /// <summary>
        /// 获取本次还没有发送过的地址邮件
        /// </summary>
        /// <param name="cuont"></param>
        /// <returns></returns>
        public static string[] GetUnSendEmailAddress(int cuont)
        {
            using (var db = new DBDataContext())
            {
                var emails= db.QQEmail.Where(x => x.HasSend ==false||x.HasSend.Equals(null)).OrderByDescending(x=>x.CreateOn).Take(cuont).Select(x=>x.Email);
                return emails.ToArray();
            }
        }
        /// <summary>
        /// 获取本次还没有发送过的地址邮件，选择活跃用户
        /// </summary>
        /// <param name="cuont"></param>
        /// <returns></returns>
        public static string[] GetUnSendAndActivitiesUserEmailAddress(int cuont)
        {
            using (var db = new DBDataContext())
            {
                var emails = db.QQEmail.Where(x => (x.HasSend == false || x.HasSend.Equals(null)) && x.ShuoShuoCount > 10).OrderByDescending(x => x.CreateOn).Take(cuont).Select(x => x.Email);
                return emails.ToArray();
            }
        }
        /// <summary>
        /// 更新邮箱是否已经发送邮件
        /// </summary>
        /// <param name="qqmail"></param>
        /// <param name="send"></param>
        public static void UpdateqqEmailHasSend(string qqmail,bool send)
        {
            using (var db = new DBDataContext())
            {
                var acount = db.QQEmail.FirstOrDefault(x => x.Email == qqmail);
                if (acount != null) acount.HasSend = send;
                db.SubmitChanges();
            }
        }
    }
}
